		var timer_is_on = 0;
    	var totalTime = 0;
    	var hours = 0;
    	var mins = 0;
    	var secs = 0;
    	var t;
    	
		function pauzeStart(user) {
			hideAll();
			showEl("pauzetekst");
			stopTimer();
			formFunction("pauze", user);
			
		}
		function pauzeStop(user){
			hideAll();
			showEl("studeren");
			resumeTimer();
			formFunction("hervat", user);
		}
		
		// Tonen of verbergen
		function hideAll(){
    		$("#pauzetekst").hide("slow");
    		$("#studeren").hide("slow");
    	}
		function showEl(name){
			$("#" + name).show("slow");
		}
		function showOnlyEl(name){
			hideAll();
			showEl(name);
		}
		
		// Timerfuncties
		function startTimer(duurInMinString)
    	{
			var duurInMin = parseInt(duurInMinString);
			if(duurInMin != null){
				if(!isNaN(duurInMin)) {
					if(duurInMin != 0){
					hours = (duurInMin - duurInMin%60)/60;
					mins = duurInMin%60;
					secs = 0;
					timer_is_on=1;
					}
					else {
					hours = 0;
					mins = 0;
					secs = 0;
					timer_is_on=1;	
					}
				}
				else{
					hours = 0;
					mins = 0;
					secs = 0;
					timer_is_on=1;
				}
			}
			else {
				hours = 0;
				mins = 0;
				secs = 0;
				timer_is_on=1;
			}
			
    		if (timer_is_on)
    		{
    			t=setInterval("addSec()",1000);
    		}
    	}
		function resumeTimer()
		{
			timer_is_on=1;
			t=setInterval("addSec()",1000);
		}
    	function stopTimer()
    	{
    		timer_is_on = 0;
    		t=window.clearInterval(t);
    	}

		function displayTimer()
		{
			document.getElementById("timer").innerHTML=doubleUp(hours)+":"+doubleUp(mins)+":"+doubleUp(secs);
		}
    	function addSec()
    	{
    		secs++;
    		if(secs==60){
    			secs = 0;
    			addMin();
    		}
    		displayTimer();
    	}
    	function addMin()
    	{
    		mins++;
    		if(mins==60){
    			mins = 0;
    			addHour();
    		}
    		displayTimer();
    	}
    	function addHour()
    	{
    		hours++;
    		displayTimer();
    	}
		function doubleUp(number)
		{
			retStr = ""+number;
			if(number<10){
				retStr = "0"+number;
			}
			return retStr;
		}
    	
    	// Ajax
    	function getXMLObject()  //XML OBJECT
    	{
    	   var xmlHttp = false;
    	   try {
    	     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
    	   }
    	   catch (e) {
    	     try {
    	       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
    	     }
    	     catch (e2) {
    	       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
    	     }
    	   }
    	   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    	     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
    	   }
    	   return xmlHttp;
    	}
    	 
    	var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object
    	 
    	function formFunction(formName, user) {
    	  if(xmlhttp) {
    	    xmlhttp.open("GET",'/opmeten?'+formName+"='true'&userId="+user, true);
    	    xmlhttp.send();
    	  }
    	}
    	 
    	function handleServerResponse() {
    	   if (xmlhttp.readyState == 4) {
    	     if(xmlhttp.status == 200) {
    	    	 
    	     }
    	     else {
    	        alert("Error during AJAX call. Please try again");
    	     }
    	   }
    	}
		